package io.memorystream;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FibonacciFile {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		ByteArrayOutputStream bout = new ByteArrayOutputStream(80);
		DataOutputStream dout = new DataOutputStream(bout);
		int f1 = 1;
		int f2 = 1;

		dout.writeInt(f1);
		dout.writeInt(f2);
		for (int i = 3; i <= 20; i++) {
			int temp = f2;
			f2 = f2 + f1;
			f1 = temp;
			dout.writeInt(f2);
		}
		FileOutputStream fout = new FileOutputStream("fibonacci.dat");
		try {
			bout.writeTo(fout);
			fout.flush();
		} finally {
			fout.close();
		}

	}

}
